<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script>
    $(function () {
        if ($("#applyTableId tr").length > 1) {
            $("#applyTableId").find("tr").eq(1).click();
            $("#applyTableId").find("tr").eq(1).addClass("table-selected");
        }
    });

    function delLoads(divId1, divId2, divId3, url, hrefUrl1, hrefUrl2, hrefUrl3,type) {
        if(type == "1"){
            var val = $("#itemListTable").find("tbody tr");
            if(val.length == 0){
                toastr.error('请添加药品后操作！');
                return false;
            }
        }
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    toastr.success(data.data);
                    loadDiv(divId1, hrefUrl1);
                    loadDiv(divId2, hrefUrl2);
                    loadDiv(divId3, hrefUrl3);
                } else if (data.code == "info") {
                    toastr.info(data.data);
                } else {
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }

    function printPresc(applyId, clinicId, patientId) {
        var val = $("#itemListTable").find("tbody tr");
        if(val.length == 0){
            toastr.error('请添加药品后操作！');
            return false;
        }
        var applyOn = $("#applyTableId .table-selected ").find("td").eq(1).text();
        printPdf('${ctx}/doctor/prescriptionApply/printPresc', 'applyId=' + applyId + '&clinicId=' + clinicId + '&patientId=' + patientId);
    }

    <%--function buildTemplate(applyId) {--%>
        <%--$.get("${ctx}/doctor/prescriptionApply/buildTemplate?applyId=" + applyId, function (data) {--%>
            <%--loadDiv(divId1, hrefUrl1);--%>
        <%--})--%>
    <%--}--%>
</script>
<div class="panel-body">
    <table class="table table-bordered mg-t datatable" id="applyTableId">
        <thead>
        <tr>
            <th>处方号</th>
            <th>申请时间</th>
            <th>类别</th>
            <th>费用/元</th>
            <th>收费状态</th>
            <th>发药状态</th>
            <th>保存状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="apply">
            <tr onclick="applyClick('${apply.id}',this,'0')">
                <td style="display: none">${apply.id}<input type="hidden" value="${apply.implementDept}"></td>
                <td>${apply.applyOn}</td>
                <td><fmt:formatDate value="${apply.createDate}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                <td><input type="hidden" value="${apply.itemClass}"><c:if
                        test="${apply.itemClass eq 'A'}">西药</c:if><c:if test="${apply.itemClass eq 'B'}">草药</c:if></td>
                <td>${apply.totalCosts}</td>
                <td><input type="hidden"
                           value="${apply.chargeFlag}">${fns:getDictLabels(apply.chargeFlag, 'NO_CHARGE', '')} </td>
                <td>${fns:getDictLabels(apply.confirmFlag, 'YES_NO', '')}</td>
                <td><input type="hidden"
                           value="${apply.prescStatus}">${fns:getDictLabels(apply.prescStatus, 'YES_NO', '')}</td>
                <td><c:choose>
                    <c:when test="${apply.chargeFlag eq '0'}">
                        <a href="#" class="btn btn-danger btn-xs"
                           onclick="confirmExtend('确认要删除该处方吗？',function(){delLoads('applyDiv','prescWesternItemDiv','prescChineseItemDiv','${ctx}/doctor/prescriptionApply/delete?id=${apply.id}&inoroutFlag=${apply.inoroutFlag}','${ctx}/doctor/prescriptionApply/applyIndex?clinicId=${prescriptionApply.clinicId}&patientId=${prescriptionApply.patientId}','${ctx}/doctor/prescriptionItem/index?applyId=${apply.id}&inoroutFlag=0','${ctx}/doctor/prescriptionItem/chineseIndex?applyId=${apply.id}&inoroutFlag=0')})">删除</a>
                        <a href="#"
                           class="btn btn-warning btn-xs"
                           onclick="printPresc('${apply.id}','${prescriptionApply.clinicId}','${prescriptionApply.patientId}')">打印</a>
                        <c:if test="${ apply.itemClass eq 'A'}">
                            <c:choose>
                                <c:when test="${ apply.isTemplate eq null }">
                                    <a href="#"
                                       class="btn btn-warning btn-xs"
                                       onclick="confirmExtend('确定要生成模板吗？',function(){delLoads('applyDiv','prescWesternItemDiv','prescChineseItemDiv','${ctx}/doctor/prescriptionApply/buildTemplate?applyId=${apply.id}','${ctx}/doctor/prescriptionApply/applyIndex?clinicId=${prescriptionApply.clinicId}&patientId=${prescriptionApply.patientId}','${ctx}/doctor/prescriptionItem/index?applyId=${apply.id}&inoroutFlag=0','${ctx}/doctor/prescriptionItem/chineseIndex?applyId=${apply.id}&inoroutFlag=0','1')})">生成模板</a>
                                </c:when>
                                <c:otherwise>模板已生成</c:otherwise>
                            </c:choose>
                        </c:if>
                    </c:when>
                    <c:when test="${apply.chargeFlag == '1' && apply.itemClass eq 'B' && apply.confirmFlag == '1'}"></c:when>
                    <c:when test="${apply.chargeFlag == '1'}">
                        <a href="#" class="btn btn-success btn-xs"
                           onclick="confirmExtend('确定要退费吗？',function(){delLoads('applyDiv','prescWesternItemDiv','prescChineseItemDiv','${ctx}/finance/refundChargesApply/save?ordersId=${apply.ordersId}&applyType=3&confirmFlag=${apply.confirmFlag}','${ctx}/doctor/prescriptionApply/applyIndex?clinicId=${prescriptionApply.clinicId}&patientId=${prescriptionApply.patientId}','${ctx}/doctor/prescriptionItem/index?applyId=${apply.id}&inoroutFlag=0','${ctx}/doctor/prescriptionItem/chineseIndex?applyId=${apply.id}&inoroutFlag=0')})">退费</a>
                        <a href="#"
                           class="btn btn-warning btn-xs"
                           onclick="printPresc('${apply.id}','${prescriptionApply.clinicId}','${prescriptionApply.patientId}')">打印</a>
                        <c:if test="${ apply.itemClass eq 'A'}">
                            <c:choose>
                                <c:when test="${apply.isTemplate eq null }">
                                    <a href="#"
                                       class="btn btn-warning btn-xs"
                                       onclick="confirmExtend('确定要生成模板吗？',function(){delLoads('applyDiv','prescWesternItemDiv','prescChineseItemDiv','${ctx}/doctor/prescriptionApply/buildTemplate?applyId=${apply.id}','${ctx}/doctor/prescriptionApply/applyIndex?clinicId=${prescriptionApply.clinicId}&patientId=${prescriptionApply.patientId}','${ctx}/doctor/prescriptionItem/index?applyId=${apply.id}&inoroutFlag=0','${ctx}/doctor/prescriptionItem/chineseIndex?applyId=${apply.id}&inoroutFlag=0','1')})">生成模板</a>
                                </c:when>
                                <c:otherwise>模板已生成</c:otherwise>
                            </c:choose>
                        </c:if>
                    </c:when>

                    <c:when test="${apply.chargeFlag == '3'}">
                        申请退费中
                    </c:when>
                    <c:when test="${apply.chargeFlag == '5'}">
                        药房退药中
                    </c:when>
                    <c:otherwise>
                    </c:otherwise>
                </c:choose>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
